﻿using System;
using System.Data;
using System.Data.Common;
using ylyfDataConnectionManager.Command;

namespace ylyfDataConnectionManager.Transaction
{
    public class HiDbTransactionChain
    {
        private HiDbTransaction Transaction { get; set; }
        internal HiDbTransactionChain(HiDbTransaction tran)
        {
            Transaction = tran ?? throw new NullReferenceException();
        }

        public void Commit()
        {
            Transaction.Commit();
        }

        public void RollBack()
        {
            Transaction.Rollback();
        }

        public HiDbTransactionChain Execute(DbCommand command)
        {
            Transaction.ExecuteNonQuery(command);
            return this;
        }

        public HiDbTransactionChain Execute(HiDbCommand command)
        {
            Transaction.ExecuteNonQuery(command);
            return this;
        }

        public HiDbTransactionChain Execute(string CommandText, CommandType SqlType, DbParameter parameter = null)
        {
            Transaction.ExecuteNonQuery(CommandText, SqlType, parameter);
            return this;
        }

        public HiDbTransactionChain Execute(string CommandText, CommandType SqlType, DbParameter[] parameters)
        {
            Transaction.ExecuteNonQuery(CommandText, SqlType, parameters);
            return this;
        }
    }
}